﻿using System;
using System.Data;
using System.Data.Entity;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TruckingApplication.Dal.EntityModels;
 
namespace TruckingApplication.Web.Tests
{
    [TestClass]
    public class DAL_MockTest
    {
        
        private TRUCKING_FRAMEWORK_Entities_2 entities = new TRUCKING_FRAMEWORK_Entities_2();
        
        [TestMethod]
        public void CanGetActiveOrders()
        {
            // Arrange

            // Act
            var orders = entities.ORDERs.Where(o => o.active == true).ToList();

            // Assert
            Assert.IsTrue(orders.Count > 0);
        }

        [TestMethod]
        public void CanUpdateOrderDueDate()
        {
            // Arrange

            // Act
            var newDueDate = new DateTime(2012, 11, 28);
            var allOrders = entities.ORDERs.Where(o => o.active == true).ToList();
            var orderCountBeforeUpdate = allOrders.Count;

            var thisOrder = allOrders.ElementAt(0);
            ORDER newOrder = new ORDER();
            newOrder.orderNum = thisOrder.orderNum;
            newOrder.dispatcherID = thisOrder.dispatcherID;
            newOrder.gross = thisOrder.gross;
            newOrder.net = thisOrder.net;
            newOrder.carrierRate = thisOrder.carrierRate;
            newOrder.max = thisOrder.max;
            newOrder.paidStatus = thisOrder.paidStatus;
            newOrder.dueDate = newDueDate;
            newOrder.mileage = thisOrder.mileage;
            newOrder.deadHeadMileage = thisOrder.deadHeadMileage;
            newOrder.quickPay = thisOrder.quickPay;
            newOrder.lumperFee = thisOrder.lumperFee;
            newOrder.brokerID = thisOrder.brokerID;
            newOrder.carrierID = thisOrder.carrierID;
            newOrder.pickupCity = thisOrder.pickupCity;
            newOrder.pickupState = thisOrder.pickupState;
            newOrder.dropOffCity = thisOrder.dropOffCity;
            newOrder.dropOffState = thisOrder.dropOffState;
            newOrder.statusID = thisOrder.statusID;
            newOrder.notes = thisOrder.notes;
            newOrder.resourceID = thisOrder.resourceID;
            newOrder.active = true;

            entities.ORDERs.Add(newOrder);
            entities.Entry(newOrder).State = EntityState.Added;

            entities.SaveChanges();

            var allOrdersAfterUpdate = entities.ORDERs.Where(o => o.active == true).ToList();
            var orderCountAfterUpdate = allOrdersAfterUpdate.Count;

            // Assert
            Assert.IsTrue(orderCountBeforeUpdate == orderCountAfterUpdate);
        }

        [TestMethod]
        public void CanGetCompanyResources()
        {
            // Arrange
            long companyID = 3;

            // Act
            var resourcesForMyCompany =
                entities.RESOURCE_COMPANY.Where(
                    rc => rc.companyID == companyID).Include(r => r.RESOURCE).Include(x => x.RESOURCE.RESOURCE_TYPE).ToList();

            // Assert
            Assert.IsTrue(resourcesForMyCompany.Count > 0);

        }
    }
}
